<?php echo $this->fetch('header.html'); ?> 

<div class="row">
  <div class="span12"> <?php echo $this->fetch('coupon/nav.html'); ?>
    <form method='post' action='/admin.php?m=coupon&a=save'>
      <input type='hidden' name='id' style='display:none;' value='<?php echo $this->_var['data']['id']; ?>' >
      <table class='table table-bordered' width='100%'>
        <tr>
          <td width="100">名称：</td>
          <td><input type='text' name='title' id='title' value='<?php echo $this->_var['data']['title']; ?>' ></td>
        </tr>
        <tr>
          <td>类型：</td>
          <td>
          		<select name="type_id"   >
                	<?php $_from = $this->_var['type_list']; if (!is_array($_from) && !is_object($_from)) { $_from=array();}; $this->push_vars('k', 'c');if (count($_from)):
    foreach ($_from AS $this->_var['k'] => $this->_var['c']):
?>
                	<option value="<?php echo $this->_var['k']; ?>" <?php if ($this->_var['data']['type_id'] == $this->_var['k']): ?> selected="selected"<?php endif; ?>><?php echo $this->_var['c']; ?></option>
                    <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
                </select>
          </td>
        </tr>
        <tr>
          <td>抵消价格：</td>
          <td><input type='text' name='money' id='money'    value='<?php echo $this->_var['data']['money']; ?>' ></td>
        </tr>
        
        <tr>
          <td>最低消费价格：</td>
          <td><input type='text' name='lower_money' id='lower_money'    value='<?php echo $this->_var['data']['lower_money']; ?>' ></td>
        </tr>
        
        <tr>
          <td>总数量：</td>
          <td><input type='text' name='amount' id='amount'   value='<?php echo $this->_var['data']['amount']; ?>' ></td>
        </tr>
        <tr>
          <td>领取数量：</td>
          <td><input type='text' name='get_num' id='get_num'   value='<?php echo $this->_var['data']['get_num']; ?>' ></td>
        </tr>
        
        <tr>
          <td>使用数量：</td>
          <td><input type='text' name='use_num' id='use_num'    value='<?php echo $this->_var['data']['use_num']; ?>' ></td>
        </tr>
        <tr>
          <td>图片地址：</td>
          <td><div class="btn-upload" style="">
              <input type="file" class="btn-upload-file"   onChange="uploadimg()"  name="upimg" id="upimg" />
            </div>
            <input type='hidden' name='imgurl' id='imgurl' value='<?php echo $this->_var['data']['imgurl']; ?>' >
            <label  id="loading" style="color:red; display:none;">正在上传中...</label>
            <span id="imgShow"> <?php if ($this->_var['data']['imgurl']): ?> <img src="/<?php echo $this->_var['data']['imgurl']; ?>.100x100.jpg"> <?php endif; ?> </span></td>
        </tr>
        
        <tr>
          <td>截止日期：</td>
          <td><input type='text' name='end_time' id='end_time'   value='<?php if ($this->_var['data']): ?><?php echo date("Y-m-d H:i:s",$this->_var['data']['end_time']); ?><?php endif; ?>'  onClick="WdatePicker({startDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd HH:mm'})" ></td>
        </tr>
        <?php if ($this->_var['data']): ?>
        <tr>
          <td>创建时间：</td>
          <td><?php echo date("Y-m-d H:m",$this->_var['data']['dateline']); ?></td>
        </tr>
        <?php endif; ?>
        <tr>
          <td>状态：</td>
          <td><input type='radio' name='status' id='status' value='1' <?php if ($this->_var['data']['status'] == 1): ?> checked="checked" <?php endif; ?> >
            显示
            <input type='radio' name='status' id='status' value='0' <?php if ($this->_var['data']['status'] != 1): ?> checked="checked" <?php endif; ?>>
            隐藏 </td>
        </tr>
        
        
        
        <tr>
          <td></td>
          <td><input type='submit' value='保存' class='btn btn-success'></td>
        </tr>
      </table>
    </form>
  </div>
</div>
<script language="javascript" src="/plugin/My97DatePicker/WdatePicker.js"></script>
<script language="javascript" src="/plugin/jquery/ajaxfileupload.js"></script> 
<script language="javascript">
   function uploadimg()
    {
		 
        //starting setting some animation when the ajax starts and completes
        $("#loading")
        .ajaxStart(function(){
            $(this).show();
        })
        .ajaxComplete(function(){
            $(this).hide();
        });

        $.ajaxFileUpload
        (
            {
                url:'/index.php?m=upload&a=uploadad&dir=coupon&t='+Math.random(), 
                secureuri:false,
                fileElementId:'upimg',
                dataType: 'json',
                success: function (data, status)
                {
                    if(typeof(data.error) != 'undefined')
                    {
                        if(data.error != '')
                        {
                           alert(data.msg);
                        }else
                        {
                             $("#imgShow").html("<img src='/"+data.imgurl+".100x100.jpg' width='100'>");
							 $("#imgurl").val(data.imgurl);
                        }
                    }
                },
                error: function (data, status, e)
                {
                    alert(e);
                }
            }
        )
        
        return false;

    }
	
  
</script> 
<script language="javascript">

$(document).ready(function(e) {
    $("#amount").bind("keyup",function(){
		$("#total_money").html($(this).val());
	});
});

</script>
<?php echo $this->fetch('footer.html'); ?>